package com.cskaoyan.classwork.work_8_06.myBatisDemo;

import com.cskaoyan.classwork.util.MyBatisUtil ;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;


public class UserDaoImpl implements UserDao {
    @Override
    public User selectByPrimaryKey(Integer id) throws Exception {
        // 1.获得全局共享的SqlSessionFactory（线程安全）
        SqlSessionFactory sqlSessionFactory = MyBatisUtil.getSqlSessionFactory();
        // 2.开启SqlSession（线程不安全），其中封装了Connection
        SqlSession sqlSession = sqlSessionFactory.openSession();
        // 3.（1）传入Sql坐标，（2）传入参数（3）查询结果集的封装
        User user = sqlSession.selectOne("usersql.selectByPrimaryKey", id);
        return user;
    }
}
